package com.studio701.carguard.controller;



import com.studio701.carguard.pojo.RespBean;
import com.studio701.carguard.pojo.UserContact;
import com.studio701.carguard.service.IUserContactService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xjc
 * @since 2022-03-28
 */
@RestController
@RequestMapping("/user-contact")
public class UserContactController {
    @Autowired
    IUserContactService iUserContactService;

    @ApiOperation("添加联系人")
    @PostMapping("/")
    public boolean insertContact(@RequestBody UserContact userContact){
        return iUserContactService.save(userContact);
    }

    @ApiOperation("修改联系人信息")
    @PutMapping("/")
    RespBean updateContact(@RequestBody UserContact userContact){
        if (iUserContactService.updateContactByUserId(userContact)){
            return RespBean.success("更新成功");
        }else {
            return RespBean.error("更新失败");
        }
    }

    @ApiOperation("删除联系人")
    @DeleteMapping("/")
    RespBean deleteContact(Integer id){
        if (iUserContactService.removeByUserId(id)){
            return RespBean.success("删除成功");
        }else {
            return RespBean.error("删除失败");
        }
    }

    @ApiOperation("获取联系人")
    @GetMapping("/")
    List<UserContact> getAllContactByUserId(Integer id){
        return iUserContactService.getAllContactByUserId(id);
    }
}
